package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketGoodsExample;
import com.cskaoyan.market.db.domain.MarketGoodsProductExample;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsProductMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 付诚
 * @Date: 2024/5/7 16:03
 * @Description:
 */
@Service
public class MarketDashboardServiceImpl implements MarketDashboardService {
    @Autowired
    private MarketGoodsMapper marketGoodsMapper;
    @Autowired
    private MarketUserMapper marketUserMapper;
    @Autowired
    private MarketGoodsProductMapper marketGoodsProductMapper;
    @Autowired
    private MarketOrderMapper marketOrderMapper;

    @Override
    public Map<String, Integer> dashboard() {
        MarketGoodsExample marketGoodsExample = new MarketGoodsExample();
        MarketGoodsProductExample marketGoodsProductExample = new MarketGoodsProductExample();
        MarketUserExample marketUserExample = new MarketUserExample();
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        int goodsTotal = (int) marketGoodsMapper.selectByExample(marketGoodsExample).stream().count();
        int productTotal = (int) marketGoodsProductMapper.selectByExample(marketGoodsProductExample).stream().count();
        int userTotal = (int) marketUserMapper.selectByExample(marketUserExample).stream().count();
        int orderTotal = (int) marketOrderMapper.selectByExample(marketOrderExample).stream().count();

        Map<String, Integer> data = new HashMap<>();
        data.put("goodsTotal", goodsTotal);
        data.put("userTotal", userTotal);
        data.put("productTotal", productTotal);
        data.put("orderTotal", orderTotal);

        return data;
    }
}
